Dates, Calender, and Status Bar

Objectives


Discussion

Date Data Type

Dim dBirthday as Date

dBirthday = #10/11/2000#

DateTime Picker and Month Calender

Date Functions and Properties

messagebox.show(Now() & " " & Today())

messagebox.show(IsDate(InputBox("enter date")))

Status Bar

Back to top


Demonstration

1.  Add a form to your Unit 2 project and make it your startup form.

2.  Add a button (btnDisplay), a MonthCalender (mcCalender), and a statusbar (sbInfo).

3.  We will now experiment with the Date type and some of the functions.  Type the following in the click event for btnDisplay:

Dim dBirthday As Date = #10/11/2001#
MessageBox.Show(dBirthday)
MessageBox.Show(IsDate(dBirthday))
MessageBox.Show(IsDate("5/22/1999"))
MessageBox.Show(IsDate("January 19, 1954"))
MessageBox.Show(IsDate("jan"))
MessageBox.Show(Now())
MessageBox.Show(Today())

4.  Run the program and click the button. Observe each messagebox and compare to the code.  Notice that IsDate returns true or false depending on whether or not the thing you pass in is a date.  Notice what Now and Today return.

5.  With the program running, experiment with the calender.  Click on a date, the year, and the month.  Notice how you can select these to change the date.  Stop your program and enter the code window.  In the left drop down box at the top of the code window select the calender control.  In the right button select the DateSelected event.  As you make this selection notice all of the events.

6.  In the DateSelected event subroutine type in the name of the calender (mcCalender) and a period (.).  Notice all of the properties and methods.  You should take some time to scroll through them.

7.  Type the following in the DateSelected event:

MessageBox.Show(mcCalender.SelectionEnd)

8.  Run the program and experiment with the calender.  Notice that you can pick a single day or a range of days.  Notice that we are displaying the SelectionEnd date.  There is also a property for the beginning of the range.

9.  Now we will experiment with the status bar.  We will start with it in its default mode. We will make the current date and time appear in it.   Type the following code into the Load event for the form:

sbInfo.Text = Now()

10.  Run your program and observe.

11.  Now we will add panels to the status bar so that we can display additional information.  In the Properties Window for the status bar change the ShowPanels property to "True".  Then click on the Panels Collection property so that the StatusBarPanels Collection Editor Window appears.  This window is used to add panels to a status bar and set the properties of the panels.  Click Add twice to add two panels. 

12.  Notice that in the StatusBarPanels Collection Editor Window there is a Name property for each panel and that the names of the panels that you just added are "StatusBarPanel1" and "StatusBarPanel2".  Change these names to "sbrNow" and "sbrSelected".  You can use these names to refer to the panels or as you will see you can use the index number of the panel to refer to it. 

13.  A status bar has a collection of panels.  The collection is zero-based which means that the first panel is referred to as panel(0), the second panel as panel(1) and so on.  Delete the current code in the Load event for the form and replace with the following code:

sbInfo.Panels(0).Text = Now()
sbInfo.Panels(1).Text = mcCalender.SelectionEnd

14. Run the program.  Notice the status bar.  Click on the calender. Notice that the date in the status bar does not change.  It's not supposed to yet because we have not programmed it to change.  We need to add the second line of code above to the DateSelected event for the calender.  Comment out all of the code in the DateSelected event and then add the following:

sbInfo.Panels(1).Text = mcCalender.SelectionEnd

15.  Now run your program and click on the calender.  

16.  Experiment with using the names of the panels.  Change the code in steps 13 and 14 so that you use the panel names in place of sbInfo.Panels().

Back to top
Exercises

1.  Write a program to experiment with the DateTimePicker, a StatusBar, and the date functions.  Your program should meet the following requirements:

  1. Your form should have a DateTimePicker control, a button, a textbox, and a StatusBar.
  2. The StatusBar should have three panels
  3. The first panel should display today's date when the form loads.
  4. The second panel should display the date selected in the DateTimePicker.
  5. When the user clicks the button, the third panel should display "True" or "False" as to whether or not the textbox contains a valid date.

 2.  Experiment with the StatusBar in #1. 

  1. How do you ensure that the contents of the panels will fit in the panels?
  2. How can you change the appearance of the panels?

3. What is the difference between "Now" and "Today"?

4.  Write a statement that declares dHoliday as a date variable and assigns July 4 to it.

Back to top

Links & Help
Back to top